import 'package:enterprise_v6_app/app/core/http/http.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/data/entities/common/risk_tree_entity.dart';
import 'package:get/get.dart';

class RegionalOrganizationTreeController extends GetxController {
  /// 组织数据
  List<RiskTreeEntity> treeList = [];

  /// 选中的节点
  RiskTreeEntity selectedEntity = RiskTreeEntity();

  /// 初始化数据列表
  Future<void> onInitData(RiskTreeEntity selectedEntity) async {
    this.selectedEntity = selectedEntity;
    if (treeList.isEmpty) {
      // 请求接口
      final res = await HttpUtil().generateGetRequest<List<RiskTreeEntity>>(Interface.etRiskIdentificationTree).execute();
      res.onSuccess((result) {
        if (result.data != null) {
          treeList = result.data!;
          update();
        }
      });
    }
  }

  /// 点击节点
  Future<void> clickOnNode(RiskTreeEntity treeEntity) async {
    treeEntity.isExpand = !treeEntity.isExpand!;
    selectedEntity = treeEntity;
    update();
  }
}
